import datetime

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


class User(db.Model):
    __tablename__ = "user"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    account = db.Column(db.String(64))
    password = db.Column(db.String(225), default='')
    avatar = db.Column(db.String(64), default='')
    sex = db.Column(db.SmallInteger, default=2)
    birth_date = db.Column(db.DateTime, default=datetime.datetime.now())
    phone = db.Column(db.String(225), unique=True)
    article_count = db.Column(db.Integer, default=0)
    following_count = db.Column(db.Integer, default=0)
    fans_count = db.Column(db.Integer, default=0)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now())
    update_time = db.Column(db.DateTime, default=datetime.datetime.now(), onupdate=datetime.datetime.now())


class Relation(db.Model):
    __tablename__ = "relation"
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    target_user_id = db.Column(db.BigInteger, nullable=False)
    relation = db.Column(db.SmallInteger, default=1)
    user_id = db.Column(db.BigInteger, nullable=False)
    is_deleted = db.Column(db.SmallInteger, default=0)


class Channel(db.Model):
    __tablename__ = "new_channel"
    """
    新闻频道
    """

    id = db.Column('channel_id', db.Integer, primary_key=True)
    name = db.Column(db.String(64), nullable=False, unique=True)
    sequence = db.Column(db.Integer, default=0)
    is_visible = db.Column(db.Boolean, default=False)
    is_default = db.Column(db.Boolean, default=False)

    create_time = db.Column(db.DateTime, default=datetime.datetime.now())
    update_time = db.Column(db.DateTime, default=datetime.datetime.now(), onupdate=datetime.datetime.now())


class UserChannel(db.Model):
    __tablename__ = "news_user_channel"
    """
    用户关注频道表
    """
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer)
    channel_id = db.Column(db.Integer)
    is_deleted = db.Column(db.Boolean, default=1)
    update_time = db.Column(db.DateTime, default=datetime.datetime.now(), onupdate=datetime.datetime.now())
    sequence = db.Column(db.Integer, default=0)


# class Article(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     user_id = db.Column(db.Integer, db.ForeignKey('user_basic.user_id'))
#     channel_id = db.Column(db.Integer, db.ForeignKey('news_channel.channel_id'))
#     title = db.Column(db.String)
#     is_advertising = db.Column(db.Boolean, default=False)
#     ctime = db.Column(db.DateTime, default=datetime.datetime.now)
#     status = db.Column(db.Integer, default=0)
#     reviewer_id = db.Column(db.Integer)
#     review_time = db.Column(db.DateTime)
#     delete_time = db.Column(db.DateTime)
#     comment_count = db.Column(db.Integer, default=0)
#     allow_comment = db.Column(db.Boolean, default=True)
#     reject_reason = db.Column(db.String)
#     utime = db.Column(db.DateTime, default=datetime.datetime.now)


